package com.mhz.echartsdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mhz.echartsdemo.pojo.Movie;
import com.mhz.echartsdemo.mapper.MovieMapper;
import com.mhz.echartsdemo.service.MovieService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mhz
 * @since 2021-04-01
 */
@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie> implements MovieService {

    @Override
    public List<Map<String, String>> getChartData() {
        String name = "";
        List<Map<String,String>> list = new ArrayList<>();
        double begin = 0;
        double end = 0;
        for (int i = 0; i < 5; i++) {
            QueryWrapper<Movie> wrapper = new QueryWrapper<>();
            Map<String,String> map = new HashMap<>();
            begin = i*2+0.1;
            end = i*2+2;
            wrapper.ge("douban_score",begin).le("douban_score",end);
            Integer value = baseMapper.selectCount(wrapper);
            name = begin + "~" + end;
            map.put("name",name);
            map.put("value",value.toString());
            list.add(map);
        }
        return list;
    }
}
